#iChannel0 "https://liutianpeng.github.io/image/1.png"

vec3 GX[3];
vec3 GY[3];

//初始化卷积矩阵
//为毛不能直接 const float G[3]={1.0, 2.0, 3.0};
void initG(){
  GX[0] = vec3(-1, -2, -1);
  GX[1] = vec3(0, 0, 0);
  GX[2] = vec3(1, 2, 1);

  GY[0] = vec3(1, 0, -1);
  GY[1] = vec3(2, 0, -2);
  GY[2] = vec3(1, 0, -1);
}

float alpha(vec4 color){
  if (color.a>0.5){ return 1.0;}
  return 0.0;
  //return color.r * 0.212 + color.g * 0.715 + color.b * 0.072;
}

void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
  initG();

  vec2 uv = gl_FragCoord.xy/iResolution.xy;
  vec4 col = texture2D(iChannel0, uv);
  
  float gx = 0.0;
  float gy = 0.0;
  for (int i=0; i<=2; i++){
    {
      vec4 c = texture2D(iChannel0, vec2(fragCoord.x+float(i),fragCoord.y)/iResolution.xy);
      gx += (alpha(c)*GX[i].x);
      gy += (alpha(c)*GY[i].x);
    }
    {
      vec4 c = texture2D(iChannel0, vec2(fragCoord.x+float(i+1),fragCoord.y+1.0)/iResolution.xy);
      gx += (alpha(c)*GX[i].y);
      gy += (alpha(c)*GY[i].y);
    }
    {
      vec4 c = texture2D(iChannel0, vec2(fragCoord.x+float(i+2),fragCoord.y+2.0)/iResolution.xy);
      gx += (alpha(c)*GX[i].z);
      gy += (alpha(c)*GY[i].z);
    }
  }
  float g = (abs(gx)+abs(gy))/9.0;
  if(g>0.1){
    fragColor = vec4(1,0,0,1);
  }else{
    fragColor = col;
    /*
    if (alpha(col)==1.0){
      fragColor = vec4(0.5,0.5,0.5,1);
    }else{
      fragColor = vec4(0,0,0,0);
    }
    */
  }
}